home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / v3_1 / sbp3_1e.lzh / PRECEDES.PL < prev    next >
Text File  |  1991-10-31  |  769b  |  34 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5.  
  6. /* PRECEDES.PL */
  7.  
  8. /* Predicates that can be used in place of < to
  9.    compare and sort objects other than numbers  */
  10.  
  11.  
  12. /*
  13.  * string_precedes(X,Y)
  14.  *   True if X precedes Y in alphabetical order,
  15.  *   where X and Y are strings (lists of ASCII codes).
  16.  */
  17.  
  18. string_precedes([],_).
  19.  
  20. string_precedes([X|_],[Y|_]) :- X<Y.
  21.  
  22. string_precedes([X|Y],[X|Z]) :- string_precedes(Y,Z).
  23.  
  24.  
  25. /*
  26.  * atom_precedes(X,Y)
  27.  *   Like string_precedes, but uses atoms.
  28.  */
  29.  
  30. atom_precedes(X,Y) :- name(X,X1),
  31.                       name(Y,Y1),
  32.                       string_precedes(X1,Y1).
  33.  
  34.